package com.itheima.d6_synchronized_lock;


import java.util.concurrent.locks.Lock;

public class Ticket implements Runnable {
    private int ticket = 100;
    public Lock luck;

    @Override
    public void run() {
        while (true) {
            luck.lock();
            if (ticket <= 0) {
                luck.unlock();
                break;
            } else {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                ticket--;
                System.out.println(Thread.currentThread().getName() + "卖出一张，还剩" + ticket + "张票");
            }

        }
    }
}

